import { userAccountLogin } from '@/api/user'

const user = {
  namespaced: true,
  state: () => ({
    //  18.1 为了让token登入页密码储存到本地，先获取
    profile: {

    }
  }),
  mutations: {
    // 18.1修改上面state的数据
    setProfile (state, userInfo) {
      state.profile = userInfo
    },
    // 19.1清除state数据==token
    clearProfile (state) {
      state.profile = {}
    }
  },

  actions: {
    // 18.1调接口，发送请求，
    async userAccountLoginToken (ctx, { account, password }) {
      // 把用户数据通过调用mutataion函数存起来
      const res = await userAccountLogin({ account, password })
      ctx.commit('setProfile', res.result)
    }

  },
  getters: {}
}
export default user// 默认导出
